package com.taxinfo.view.declaration;

import com.taxinfo.pojo.dto.DecDocumentRecDto;
import com.taxinfo.service.AccBalMapInfoService;
import com.taxinfo.service.DecDocumentRecService;
import com.taxinfo.utils.SpringUtil;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;

import java.math.BigDecimal;
import java.util.List;


/**
 * @author wanghy
 * @version 1.0
 */
public class DecFileViewTable extends TableView<DecDocumentRecDto> {

    private final DecDocumentRecService decDocumentRecService = (DecDocumentRecService) SpringUtil.getBean("DecDocumentRecServiceImpl");

    private final ObservableList<DecDocumentRecDto> items = FXCollections.observableArrayList();

    private final TableColumn<DecDocumentRecDto, String> decFileName = new TableColumn<>("申报文件名");
//    private final TableColumn<DecDocumentRecDto, String> decFileAddr = new TableColumn<>("申报文件地址");
    private final TableColumn<DecDocumentRecDto, String> createTime = new TableColumn<>("生成时间");
    private final TableColumn<DecDocumentRecDto, String> isSb = new TableColumn<>("是否已上报");

    public DecFileViewTable(String id) {
        setItems(items);
        initColumns();
        showAllData(id);
    }

    private void initColumns() {

        decFileName.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getDecFileName()));
        decFileName.setPrefWidth(500);
//        decFileAddr.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getDecFileAddr()));
//        decFileAddr.setPrefWidth(500);
        createTime.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getCreateTime()));
        createTime.setPrefWidth(200);
        isSb.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getIsSb()));
        isSb.setPrefWidth(100);
        ObservableList<TableColumn<DecDocumentRecDto, ?>> cols = getColumns();
        cols.add(decFileName);
        cols.add(createTime);
//        cols.add(decFileAddr);
        cols.add(isSb);
     }

    public void showAllData(String id) {
        items.clear();
        List<DecDocumentRecDto> vos = decDocumentRecService.selectDataByParentId(id);
        if (vos == null){
            return;
        }
        items.addAll(vos);
    }

}
